//
//  ContentController.m
//  oschina_song
//
//  Created by song on 16/1/25.
//  Copyright © 2016年 song. All rights reserved.
//

#import "ContentController.h"
#import "NewsController.h"
#import "BlogController.h"
#import "UIColor+utils.h"
#import "UIView+Utils.h"
#import "SwipableViewController.h"
#import "RESideMenu.h"
#import "TweetsViewController.h"
@interface ContentController ()
{

}

@property(nonatomic , assign) CGFloat screenHeight;
@property(nonatomic , assign) CGFloat screenWidth;

@end

@implementation ContentController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NewsController *newsCtl  = [[NewsController alloc] initWithNewsListType:NewsListTypeNews];
    NewsController *hotnewCtl = [[NewsController alloc] initWithNewsListType:NewsListTypeAllTypeWeekHottest];
    BlogController *blogViewCtl = [[BlogController alloc] initWithBlogsType:BlogTypeLatest];
    BlogController *recommentBlogCtl =[[BlogController alloc] initWithBlogsType:BlogTypeRecommended];
    
    
    TweetsViewController *newTweetCtl =[[TweetsViewController alloc] initWithTweetsType:TweetsTypeAllTweets];
    TweetsViewController *hotTweetCtl = [[TweetsViewController alloc] initWithTweetsType:TweetsTypeHotestTweets];
    TweetsViewController *myTweetCtl = [[TweetsViewController alloc] initWithTweetsType:TweetsTypeOwnTweets];
    
    
    
    SwipableViewController *newvc =[[SwipableViewController alloc] initWithTitle:@"综合" addSubTitles:@[@"咨询",@"热点",@"博客",@"推荐"] andControllers:@[newsCtl,hotnewCtl,blogViewCtl,recommentBlogCtl]];
    
    SwipableViewController *tweetvc =[[SwipableViewController alloc] initWithTitle:@"动弹" addSubTitles:@[@"最新动弹",@"热门动弹",@"我的动弹"] andControllers:@[newTweetCtl,hotTweetCtl,myTweetCtl]];
    
    UINavigationController *discovernav = [[UIStoryboard storyboardWithName:@"Discover" bundle:nil] instantiateViewControllerWithIdentifier:@"nav"];
    
    UINavigationController *menav = [[UIStoryboard storyboardWithName:@"me" bundle:nil] instantiateViewControllerWithIdentifier:@"nav"];
    
    
    self.viewControllers = @[
                             [self addNavigationItemForViewController:newvc] ,
                             [self addNavigationItemForViewController:tweetvc] ,
                             [UIViewController new], discovernav , menav
                             ];
    
    NSArray *title = @[@"综合",@"动弹",@"",@"发现",@"我"];
    NSArray *images  = @[@"tabbar-news", @"tabbar-tweet", @"", @"tabbar-discover", @"tabbar-me"];
    
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull item , NSUInteger idx, BOOL * _Nonnull stop){
        [item setTitle:title[idx]];
        [item setImage:[UIImage imageNamed:images[idx]]];
    }];
    
     [self addCenterButtonWithImage:[UIImage imageNamed:@"tabbar-more"]];

}

-(UINavigationController *)addNavigationItemForViewController:(UIViewController *)vc
{
    UINavigationController *navvc = [[UINavigationController alloc] initWithRootViewController:vc];
    vc.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationbar-sidebar"] style:UIBarButtonItemStylePlain target:self action:@selector(onClickMenuButton)];
    
    
    vc.navigationItem.rightBarButtonItem  =[ [UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(pushSearchViewController)];
    
    return navvc;
}

-(void)onClickMenuButton
{
    [self.sideMenuViewController presentLeftMenuViewController];
}

-(void)pushSearchViewController
{
    
}

-(void)addCenterButtonWithImage:(UIImage *)image
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    _screenHeight = self.view.frame.size.height;
    _screenWidth = self.view.frame.size.width;
    
    CGPoint origin  =  [self.view convertPoint:self.tabBar.center toView:self.tabBar];
    CGSize  btnsize =CGSizeMake(self.tabBar.frame.size.width / 5 -6  , self.tabBar.frame.size.height -4 );
    btn.frame  = CGRectMake(origin.x - btnsize.height /2, origin.y - btnsize.height /2, btnsize.height, btnsize.height);
    
    [btn setCornerRadius:btnsize.height /2];
    
    [btn setImage:image forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor colorWithHex:0x24a83d]];
    [self.tabBar addSubview:btn];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
